package sdk.webview.fmc.com.fmcsdk.view;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import sdk.webview.fmc.com.fmcsdk.R;


/**
 * 纯用于测试的diglog，弹出想要的信息
 */
public class ShowMsgDialog extends Dialog {
    private Context context;
    /**
     * 标题和内容
     */
    private String msg;

    private TextView confirm;
    private TextView tv_message;

    //只有提示内容的消息框
    public ShowMsgDialog(Context context, String msg) {
        super(context, R.style.Dialog);
        this.context = context;
        this.msg = msg;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.error_dialog);
        confirm = (TextView) findViewById(R.id.confirm);
        TextView cancel = (TextView) findViewById(R.id.cancel);
        tv_message = (TextView) findViewById(R.id.tv_message);
        tv_message.setText(msg);
        TextView look_detail = (TextView) findViewById(R.id.look_detail);
        confirm.setOnClickListener(new clickListener());
        cancel.setVisibility(View.GONE);
        look_detail.setVisibility(View.GONE);
        //试着提示框的位置和大小
        Window dialogWindow = getWindow();
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        DisplayMetrics d = context.getResources().getDisplayMetrics(); // 获取屏幕宽、高
        lp.width = (int) (d.widthPixels * 0.9);
        dialogWindow.setAttributes(lp);

    }

    public void setConfirmText(String text) {
        confirm.setText(text);
    }


    private class clickListener implements View.OnClickListener {
        @Override
        public void onClick(View v) {
            int id = v.getId();
            if (id == R.id.confirm) {
                dismiss();
            }
        }

    }


}
